package com.lancoo.answer.helper;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.lancoo.answer.R;

/**
 * Created by pengmi on 2022/1/20 10:26
 * Description:
 */
public class ToastHelper {

    private static Toast mToast;

    public static void showToast(Context mContext,int showState,int resID){
        showToast(mContext,showState,mContext.getResources().getString(resID));
    }
    public static void showToast(Context mContext,int showState,String resID){
        if(mToast!=null){
//
            mToast.cancel();
        }
        mToast = new Toast(mContext.getApplicationContext());
        @SuppressLint("InflateParams") View toastRoot = LayoutInflater.from(mContext.getApplicationContext())
                .inflate(R.layout.ev_toast_layout, null);
        if(toastRoot==null){
            return;
        }
        mToast.setView(toastRoot);
        mToast.setDuration(Toast.LENGTH_SHORT);
        TextView tv =toastRoot.findViewById(R.id.tv_toast);
        ImageView iv = toastRoot.findViewById(R.id.iv_toast_icon);
        switch (showState){
            case 0 :
                iv.setBackgroundResource(R.drawable.ev_vector_toast_warning);
                break;
            case 1 :
                iv.setBackgroundResource(R.drawable.ev_vector_toast_correct);
                break;
            case 2 :
                iv.setBackgroundResource(R.drawable.ev_vector_toast_error);
                break;
            default:
                break;
        }
        tv.setText(resID);
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.show();
    }

    public static void cancelToast(){
        if(mToast!=null){
            mToast.cancel();
        }
    }

    /**
     *
     * @param mContext context
     */

    public static void showAudioLoadErrorToast(Context mContext) {
        showToast(mContext,2,R.string.ev_audio_load_eorr);
    }

    public static void showAudioLoadingToast(Context mContext) {
        showToast(mContext,0,R.string.ev_audio_loading);
    }
}
